/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.applicatioN.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Slim
 */
@Entity
@Table(name = "offre_d_emploi")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "OffreDEmploi.findAll", query = "SELECT o FROM OffreDEmploi o"),
    @NamedQuery(name = "OffreDEmploi.findByReference", query = "SELECT o FROM OffreDEmploi o WHERE o.reference = :reference"),
    @NamedQuery(name = "OffreDEmploi.findByDateDeDepot", query = "SELECT o FROM OffreDEmploi o WHERE o.dateDeDepot = :dateDeDepot"),
    @NamedQuery(name = "OffreDEmploi.findByEtat1", query = "SELECT o FROM OffreDEmploi o WHERE o.etat1 = :etat1"),
    @NamedQuery(name = "OffreDEmploi.findByEtat2", query = "SELECT o FROM OffreDEmploi o WHERE o.etat2 = :etat2"),
    @NamedQuery(name = "OffreDEmploi.findByNomPoste", query = "SELECT o FROM OffreDEmploi o WHERE o.nomPoste = :nomPoste"),
    @NamedQuery(name = "OffreDEmploi.findByMontantAlloue", query = "SELECT o FROM OffreDEmploi o WHERE o.montantAlloue = :montantAlloue")})
public class OffreDEmploi implements Serializable {
    @Column(name = "ETAT_1")
    private Character etat1;
    @Column(name = "ETAT_2")
    private Character etat2;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "MONTANT_ALLOUE")
    private Double montantAlloue;

    @Basic(optional = false)
    @Column(name = "DATE_DE_DEPOT", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date dateDeDepot;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "REFERENCE")
    private Integer reference;
    @ManyToMany(mappedBy = "offreDEmploiCollection")
    private Collection<Candidat> candidatCollection;
    @JoinColumn(name = "NOM_POSTE", referencedColumnName = "NOM_POSTE")
    @ManyToOne(optional = false)
    private Poste nomPoste;

    public OffreDEmploi() {
    }

    public OffreDEmploi(Integer reference) {
        this.reference = reference;
    }

    public OffreDEmploi(Integer reference, Date dateDeDepot, char etat1, char etat2, double montantAlloue) {
        this.reference = reference;
        this.dateDeDepot = dateDeDepot;
        this.etat1 = etat1;
        this.etat2 = etat2;
        this.montantAlloue = montantAlloue;
    }

    public Integer getReference() {
        return reference;
    }

    public OffreDEmploi(Date dateDeDepot, char etat1, char etat2, double montantAlloue) {
        this.dateDeDepot = dateDeDepot;
        this.etat1 = etat1;
        this.etat2 = etat2;
        this.montantAlloue = montantAlloue;
    }

    public void setReference(Integer reference) {
        this.reference = reference;
    }

    public Date getDateDeDepot() {
        return dateDeDepot;
    }

    public void setDateDeDepot(Date dateDeDepot) {
        this.dateDeDepot = dateDeDepot;
    }

    public char getEtat1() {
        return etat1;
    }

    public void setEtat1(char etat1) {
        this.etat1 = etat1;
    }

    public char getEtat2() {
        return etat2;
    }

    public void setEtat2(char etat2) {
        this.etat2 = etat2;
    }

    public double getMontantAlloue() {
        return montantAlloue;
    }

    public void setMontantAlloue(double montantAlloue) {
        this.montantAlloue = montantAlloue;
    }

    @XmlTransient
    public Collection<Candidat> getCandidatCollection() {
        return candidatCollection;
    }
    
    //Multiple candidates can be matched with one offer
    public void matchWith (Candidat c) {
        candidatCollection.add(c);
    }
    

    public void setCandidatCollection(Collection<Candidat> candidatCollection) {
        this.candidatCollection = candidatCollection;
    }

    public Poste getNomPoste() {
        return nomPoste;
    }

    public void setNomPoste(Poste nomPoste) {
        this.nomPoste = nomPoste;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (reference != null ? reference.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof OffreDEmploi)) {
            return false;
        }
        OffreDEmploi other = (OffreDEmploi) object;
        if ((this.reference == null && other.reference != null) || (this.reference != null && !this.reference.equals(other.reference))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.applicatioN.entities.OffreDEmploi[ reference=" + reference + " ]";
    }


    public void setEtat1(Character etat1) {
        this.etat1 = etat1;
    }


    public void setEtat2(Character etat2) {
        this.etat2 = etat2;
    }


    public void setMontantAlloue(Double montantAlloue) {
        this.montantAlloue = montantAlloue;
    }
}
